package com.jcoinexchage.user.business.impl;

import com.jcoinexchage.user.business.MemberLoginService;
import com.jcoinexchage.user.business.AuthTokenService;
import com.jcoinexchage.user.common.enums.ResultCodeEnum;
import com.jcoinexchage.user.common.vo.LoginPwdReq;
import com.jcoinexchage.user.common.vo.LoginTokenRes;
import com.jcoinexchage.user.repository.dao.MemberDao;
import com.jcoinexchage.user.repository.model.Member;
import com.jcoinexchange.web.auth.UserInfo;
import com.jcoinexchange.web.exception.InternalException;
import com.jcoinexchange.web.util.PasswordUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class MemberLoginServiceImpl implements MemberLoginService {
    @Resource
    private MemberDao memberDao;

    @Override
    public LoginTokenRes loginByAccountPwd(LoginPwdReq request) {
        Member member = memberDao.queryByPhoneOrEmail(request.getAccount());
        if (member == null) {
            throw new InternalException(ResultCodeEnum.USER_CODE_ERR);
        }
        if (!PasswordUtils.memberPwd(member.getPwd()).equals(member.getPwd())) {
            throw new InternalException(ResultCodeEnum.USER_CODE_ERR);
        }
        String token = generateCode(member);
        LoginTokenRes loginTokenRes = new LoginTokenRes();
        loginTokenRes.setMemberId(member.getMemberId());
        loginTokenRes.setToken(token);
        return loginTokenRes;
    }

    @Override
    public LoginTokenRes loginByEmailCode() {
        return null;
    }

    @Override
    public LoginTokenRes loginBySmsCode() {
        return null;
    }

    private String generateCode(Member member) {
        return "";
    }

}
